<template>
  <div class="icons">
    <swiper :options="swiperOption">
      <swiper-slide
        v-for="page of pages"
      >
        <div class="icon" v-for="item of page">
          <div class="icon-img">
            <img class="icon-img-content" :src="item.imgUrl">
            <p class="icons-doc">{{item.desc}}</p>
          </div>
        </div>
      </swiper-slide>
    </swiper>
  </div>
</template>

<script>

  export default {
    name: "Icons",
    props: {
      iconList: Array
    },
    data() {
      return {
        swiperOption: {
          autoplay: false
        }
      }
    },
    //  对图片数量处理，进行分页
    computed: {
      pages() {
        const pages = []  // 页的数组
        // 8个图标1页
        this.iconList.forEach((item, index) => {
          const page = Math.floor(index / 8)
          if (!pages[page]) {
            pages[page] = []
          }
          // 把各页的图标放进去
          pages[page].push(item)
        })
        return pages
      }
    }
  }
</script>

<style lang="stylus" scoped>
  @import '~styles/mixins.styl'
  .icons >>> swiper-contener
    overflow: hidden
    background-color: #25a4bb
    padding-bottom: 45.5%

  .icon
    position: relative
    overflow: hidden
    float: left
    width: 25%
    height: 0
    padding-bottom: 25%

    .icon-img
      position: absolute
      top: 0
      left: 0
      right: 0
      bottom: .44rem
      box-sizing: border-box
      padding: .1rem

      .icon-img-content
        height: 100%
        margin: 0 auto
        display: block

    .icons-doc
      margin-top: .2rem
      text-align: center
      bottom: 0
      ellipsis()

</style>
